package refactoredBankSystem;

/**
 * The CreditCard class.
 * @author (refactorers) Sagar Kamboj, Yong Yu Wang
 *
 */
public class CreditCard 
{
	/**
	 * The last credit card number.
	 */
	private static int fLastCreditCardNumber;
	
	/**
	 * The account this credit card is connected to.
	 */
	private int fAccountConnectedTo;
	
	/**
	 * The credit card number.
	 */
	private int fCreditCardNumber;
	
	/**
	 * The spending limit associated with the credit card.
	 */
	private double fLimit; // you cannot spend more than this limit
	
	/**
	 * The balance left in the account.
	 */
	private double fBalance;
	
	/**
	 * The current customer of the credit card.
	 */
	private Customer currentCustomer;
	
	/**
	 * Creates a CreditCard with the given customer.
	 * 
	 * @param newCustomer making a credit card.
	 */
	public CreditCard(final Customer newCustomer)
	{
		// Calling the second constructor.
		this(newCustomer, 2500);
	}
	
	/**
	 * Creates a CreditCard with the given customer and the given limit.
	 * 
	 * @param newCustomer making a credit card.
	 * @param limit that the customer can spend on the credit card.
	 */
	public CreditCard(final Customer newCustomer, final double limit)
	{
		currentCustomer = newCustomer;
		fLimit = limit;
		fBalance = 0;
	}
	
	/**
	 * Pays off the amount from the balance if possible.
	 * 
	 * @param amount that needs to be payed.
	 * @return if the amount was paid off or not.
	 */
	public boolean pay(final double amount)
	{
		if((fBalance - amount) < -fLimit)
		{
			fBalance -= amount;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Sets the fLastCreditCardNumber in this class to a new one.
	 * @param fLastCreditCardNumber	the new fLastCreditCardNumber to set.
	 */
	public void setFLastCreditCardNumber(int newNumber) {
		fLastCreditCardNumber = newNumber;
	}
	
	/**
	 * Gets the fLastCreditCardNumber object associated with this class.
	 * @return the fLastCreditCardNumber 
	 */
	public int getFLastCreditCardNumber() {
		return fLastCreditCardNumber;
	}
	
	/**
	 * Sets the fAccountConnectedTo in this class to a new one.
	 * @param fAccountConnectedTo	the new fAccountConnectedTo to set.
	 */
	public void setFAccountConnectedTo(final int newNumber) {
		fAccountConnectedTo = newNumber;
	}
	
	/**
	 * Gets the fAccountConnectedTo object associated with this class.
	 * @return the fAccountConnectedTo 
	 */
	public int getFAccountConnectedTo() {
		return fAccountConnectedTo;
	}
	
	/**
	 * Sets the fCreditCardNumber in this class to a new one.
	 * @param fCreditCardNumber	the new fCreditCardNumber to set.
	 */
	public void setFCreditCardNumber(final int newNumber) {
		fCreditCardNumber = newNumber;
	}
	
	/**
	 * Gets the fCreditCardNumber object associated with this class.
	 * @return the fCreditCardNumber 
	 */
	public int getFCreditCardNumber() {
		return fCreditCardNumber;
	}
	
	/**
	 * Sets the fLimit in this class to a new one.
	 * @param fLimit	the new fLimit to set.
	 */
	public void setFLimit(final double newNumber) {
		fLimit = newNumber;
	}
	
	/**
	 * Gets the fLimit object associated with this class.
	 * @return the fLimit 
	 */
	public double getFLimit() {
		return fLimit;
	}
	
	/**
	 * Sets the fBalance in this class to a new one.
	 * @param fBalance	the new fBalance to set.
	 */
	public void setFBalance(final double newNumber) {
		fBalance = newNumber;
	}
	
	/**
	 * Gets the fBalance object associated with this class.
	 * @return the fBalance 
	 */
	public double getFBalance() {
		return fBalance;
	}
	
	/**
	 * Get the current customer belonging to this class.
	 * @return	The current customer in this class.
	 */
	public Customer getCustomer() {
		return currentCustomer;
	}
	
	/**
	 * Sets the customer in this class to a new one.
	 * @param newCustomer	the new customer to set.
	 */
	public void setCustomer(final Customer newCustomer) {
		currentCustomer = newCustomer;
	}
}
